package com.marcocirillo.justweet;

import javax.swing.*;
import java.awt.*;

public class View extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5804229778148923455L;
	//private JusTweet jt;
	private JLabel usernameLabel;
	private JLabel passwordLabel;
	private JTextField usernameText;
	private JPasswordField passwordText;
	private JTextArea tweetText;
	private JButton tweetButton;
	
	public static final String USERNAME_TEXT = "Username: ";
	public static final String PASSWORD_TEXT = "Password: ";
	public static final String TWEET_TEXT = "Tweet!";
	
	public View(int width, int height/*, JusTweet jt*/)
	{
		/* Construct Window */
		super("JusTweet");
		super.setSize(width, height);
		super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		super.setLayout(/*new GridLayout(3,2)*/ new FlowLayout());
		
	    try {
	        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
	    } catch (Exception evt) {}
		
		//this.jt = jt;
		
		/* Construct Widgets */
		usernameLabel = new JLabel(View.USERNAME_TEXT);
		passwordLabel = new JLabel(View.PASSWORD_TEXT);
		usernameText = new JTextField("", 15);
		passwordText = new JPasswordField("", 15);
		passwordText.setEchoChar('*');
		tweetText = new JTextArea(4, 30);
		tweetText.setAutoscrolls(true);
		tweetButton = new JButton(View.TWEET_TEXT);
		/*JScrollPane areaScrollPane = new JScrollPane(tweetText);
		areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		//areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		areaScrollPane.setPreferredSize(new Dimension(250, 250));*/
		tweetText.setLineWrap(true);

		/* Add ActionListeners */
		tweetButton.addActionListener(new Controller(this));
		tweetButton.setActionCommand(View.TWEET_TEXT);
		/* Pack Window! */
		this.add(usernameLabel);
		this.add(usernameText);
		this.add(passwordLabel);
		this.add(passwordText);
		this.add(tweetText);
		this.add(tweetButton);
		this.pack();
		
	}
	
	public void clearTweetText()
	{
		this.tweetText.setText("");
	}
	
	public String getTweetText()
	{
		return tweetText.getText();
	}
	
	public String getUsernameText()
	{
		return usernameText.getText();
	}
	public String getPasswordText()
	{
		char[] c = passwordText.getPassword();
		String s = new String(c);
		return s;
	}
}
